aarch64: Add PubSub events to capture security state transitions
authorDimitris Papastamos <dimitris.papastamos@arm.com>
Fri, 13 Oct 2017 14:27:58 +0000 (15:27 +0100)
committerDimitris Papastamos <dimitris.papastamos@arm.com>
Tue, 31 Oct 2017 10:33:27 +0000 (10:33 +0000)
Add events that trigger before entry to normal/secure world.  The
events trigger after the normal/secure context has been restored.

Similarly add events that trigger after leaving normal/secure world.
The events trigger after the normal/secure context has been saved.

Change-Id: I1b48a7ea005d56b1f25e2b5313d77e67d2f02bc5
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
docs/firmware-design.rst
include/lib/el3_runtime/pubsub_events.h
lib/el3_runtime/aarch64/context_mgmt.c

index 853e39011577ea97bc36adea0eedc4018723a673..7cc197096b932f02f06582878eadaa8b30ac8a89 100644 (file)
@@ -2309,6 +2309,12 @@ PE only; it won't cause handlers to execute on a different PE.
 Note that publishing an event on a PE blocks until all the subscribed handlers
 finish executing on the PE.
 
+ARM Trusted Firmware generic code publishes and subscribes to some events
+within. Platform ports are discouraged from subscribing to them. These events
+may be withdrawn, renamed, or have their semantics altered in the future.
+Platforms may however register, publish, and subscribe to platform-specific
+events.
+
 Publish and Subscribe Example
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -2339,22 +2345,6 @@ implement:
 
    SUBSCRIBE_TO_EVENT(foo, foo_handler);
 
-Available Events
-~~~~~~~~~~~~~~~~
-
-ARM Trusted Firmware core makes some events available by default. They're listed
-below, along with information as to when they're published, and the arguments
-passed to subscribed handlers.
-
-Other EL3 components that are conditionally compiled in may make their own
-events available, but aren't documented here.
-
--  ``psci_cpu_on_finish``
-
-   - When: Published on a PE after it's finished its power-up sequence.
-
-   - Argument: ``NULL``.
-
 Performance Measurement Framework
 ---------------------------------
 
index 62550f81eacdffe66e2ae6fac8458c1611e4c06e..9cfedb4de78e5ff51d461f5bf8ba56be221d58fa 100644 (file)
  * initialization.
  */
 REGISTER_PUBSUB_EVENT(psci_cpu_on_finish);
+
+#ifdef AARCH64
+/*
+ * These events are published by the AArch64 context management framework
+ * after the secure context is restored/saved via
+ * cm_el1_sysregs_context_{restore,save}() API.
+ */
+REGISTER_PUBSUB_EVENT(cm_entering_secure_world);
+REGISTER_PUBSUB_EVENT(cm_exited_secure_world);
+
+/*
+ * These events are published by the AArch64 context management framework
+ * after the normal context is restored/saved via
+ * cm_el1_sysregs_context_{restore,save}() API.
+ */
+REGISTER_PUBSUB_EVENT(cm_entering_normal_world);
+REGISTER_PUBSUB_EVENT(cm_exited_normal_world);
+#endif /* AARCH64 */
index 21e86de05c87b0c85e338f331b3f4fe6e439c27c..c8232df96ffd1c647e5c3a26e81c604e3fb5cfec 100644 (file)
@@ -13,6 +13,7 @@
 #include <interrupt_mgmt.h>
 #include <platform.h>
 #include <platform_def.h>
+#include <pubsub_events.h>
 #include <smcc_helpers.h>
 #include <string.h>
 #include <utils.h>
@@ -421,9 +422,8 @@ void cm_prepare_el3_exit(uint32_t security_state)
                }
        }
 
-       el1_sysregs_context_restore(get_sysregs_ctx(ctx));
-
-       cm_set_next_context(ctx);
+       cm_el1_sysregs_context_restore(security_state);
+       cm_set_next_eret_context(security_state);
 }
 
 /*******************************************************************************
@@ -440,6 +440,13 @@ void cm_el1_sysregs_context_save(uint32_t security_state)
 
        el1_sysregs_context_save(get_sysregs_ctx(ctx));
        el1_sysregs_context_save_post_ops();
+
+#if IMAGE_BL31
+       if (security_state == SECURE)
+               PUBLISH_EVENT(cm_exited_secure_world);
+       else
+               PUBLISH_EVENT(cm_exited_normal_world);
+#endif
 }
 
 void cm_el1_sysregs_context_restore(uint32_t security_state)
@@ -450,6 +457,13 @@ void cm_el1_sysregs_context_restore(uint32_t security_state)
        assert(ctx);
 
        el1_sysregs_context_restore(get_sysregs_ctx(ctx));
+
+#if IMAGE_BL31
+       if (security_state == SECURE)
+               PUBLISH_EVENT(cm_entering_secure_world);
+       else
+               PUBLISH_EVENT(cm_entering_normal_world);
+#endif
 }
 
 /*******************************************************************************